package com.zyjc.city.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 公共线程池配置
 */
@EnableAsync
@Configuration
public class CommonThreadPoolConfig {

    @Bean("commonThreadPoolExecutor")
    public ThreadPoolExecutor  syncExecutor() {
        // 获取可用处理器的Java虚拟机的数量
        int sum = Runtime.getRuntime().availableProcessors();
        System.out.println("系统最大线程数 -> " + sum);
        // 实例化自定义线程池
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                10,
                10,
                60L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(50)

        );
        return executor;
    }
}
